Imports Clo = Enhancements.Core.Logging
Imports Fun = Enhancements.Basic.Expressions.Functions
Imports Gen = System.Collections.Generic
Imports Glo = System.Globalization
Imports Lev = Enhancements.Basic.Expressions.Levels
Imports Ope = Enhancements.Basic.Expressions.Operators
Imports Pri = Enhancements.Basic.Primitives
Imports Ref = System.Reflection
Imports Sys = System
Imports Tex = System.Text
Imports Val = Enhancements.Basic.Expressions.Values

Namespace Enhancements.Basic.Expressions
    Partial Class Compiler
        <DebuggerStepThrough()> _
            Private NotInheritable Class __ExpressionSyntacticalAnalysis

            Private Sub New()
            End Sub

            Private Const __SymbolicalCharacterForValue As System.Char = "V"c
            Private Const __SymbolicalCharacterForOperator As System.Char = "O"c
            Private Const __SymbolicalCharacterForOther As System.Char = "?"c

            ''' <exception cref="IsNullException"> </exception>
            ''' <exception cref="IsListFilledNotException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionStartsWithFunctionParametersSeparatorException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionEndsWithFunctionParametersSeparatorException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionContainsAdjacentFunctionParametersSeparatorsException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionTokenTypeIsValidNotException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionContainsAdjacentValuesOrVariablesOrFunctionCallsException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionContainsAdjacentOperatorsException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionEndsWithOperatorException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionOperatorHasNoCorrespondingFunctionSignatureException"> </exception>
            ''' <exception cref="CompilerExpressionLevelWhenEmptyMustBePrecededByFunctionNameException"> </exception>
            ''' <exception cref="CompilerExpressionFunctionNameAndParametersHaveNoCorrespondingFunctionSignatureException"> </exception>
            ''' <exception cref="CompilerExpressionLevelWhenWithTwoOrMoreParametersMustBePrecededByFunctionNameException"> </exception>
            ''' <exception cref="CompilerExpressionFunctionParametersAreOnlyAllowedInsideLevelsException"> </exception>
            ''' <exception cref="CompilerExpressionProducedNoEndResultException"> </exception>
            ''' <exception cref="CompilerExpressionRootTokenTypeIsValidNotException"> </exception>
            Friend Shared Function AssertAndDetermineExpression(ByVal _compiler As Compiler, ByVal _expression As System.String, ByVal _tokens As Gen.List(Of Token), ByVal _tokensVariables() As Variable) As Expression
                _compiler.IsNullNot("_compiler", True)
                _tokens.IsListFilled("_tokens", True)

                Do Until _tokens.Count.IsInRange("_tokens.Count", 0, 1, False)
                    Dim _deepestLevelBeginAndEndTokensExist As System.Boolean = False
                    Dim _deepestLevelBeginTokenIndex As Sys.Int32 = -1
                    Dim _deepestLevelEndTokenIndex As Sys.Int32 = -1
                    Levels.Delimiter.___FindDeepestLevelBeginAndEndTokensIndexes(_tokens, _deepestLevelBeginAndEndTokensExist, _deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex)
                    If _deepestLevelBeginAndEndTokensExist.IsTrue("_deepestLevelBeginAndEndTokensExist", False) Then
                        Dim _deepestLevelSubexpressionsOccurrences() As Primitives.Occurrence = Fun.FunctionParametersSeparator.___AssertAndFindFunctionSubexpressionsOccurrences(_expression, _tokens, _deepestLevelBeginTokenIndex + 1, _deepestLevelEndTokenIndex - 1)
                        Select Case _deepestLevelSubexpressionsOccurrences.Length
                            Case 0
                                Dim _function As Fun.Function = Nothing
                                Dim _functionFunctionSignature As Fun.FunctionSignature = Nothing
                                If _deepestLevelBeginTokenIndex.IsInRange("_deepestLevelBeginTokenIndex", 0, 0, False) Then
                                    CompilerExpressionLevelWhenEmptyMustBePrecededByFunctionNameException.___Throw(_expression, _tokens.GetRange(_deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1).ToArray())
                                Else
                                    If _tokens(_deepestLevelBeginTokenIndex - 1).IsOfTypeNot("_tokens(_deepestLevelBeginTokenIndex - 1)", GetType(Fun.FunctionName), False) Then
                                        CompilerExpressionLevelWhenEmptyMustBePrecededByFunctionNameException.___Throw(_expression, _tokens.GetRange(_deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1).ToArray())
                                    Else
                                        For Each _compilerFunction As Fun.Function In _compiler.Functions
                                            If CType(_tokens(_deepestLevelBeginTokenIndex - 1), Fun.FunctionName).Function.Is("CType(_tokens(_deepestLevelBeginTokenIndex - 1), Fun.FunctionName).Function", _compilerFunction, "_compilerFunction", False) Then
                                                For Each _compilerFunctionFunctionSignature As Fun.FunctionSignature In _compilerFunction.Signatures
                                                    If Fun.FunctionSignature.___IsCompatibleWithParameters(_compilerFunctionFunctionSignature) Then
                                                        _function = _compilerFunction
                                                        _functionFunctionSignature = _compilerFunctionFunctionSignature
                                                        Exit For
                                                    End If
                                                Next _compilerFunctionFunctionSignature
                                                Exit For
                                            End If
                                        Next _compilerFunction
                                        If _function.IsNull("_function", False) Then
                                            CompilerExpressionFunctionNameAndParametersHaveNoCorrespondingFunctionSignatureException.___Throw(_expression, _tokens.GetRange(_deepestLevelBeginTokenIndex - 1, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1).ToArray())
                                        Else
                                            _tokens.Insert(_deepestLevelBeginTokenIndex - 1, New Fun.FunctionCall(_compiler, _expression, _tokens(_deepestLevelBeginTokenIndex - 1).ExpressionBeginIndex, _tokens(_deepestLevelEndTokenIndex).ExpressionEndIndex, _function, _functionFunctionSignature, New Token() {}))
                                            _tokens.RemoveRange(_deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1)
                                        End If
                                    End If
                                End If
                            Case 1
                                Dim _subexpressionResolutionToken As Token = __AssertAndDetermineExpressionResolveSubexpression(_compiler, _expression, _tokens, _deepestLevelSubexpressionsOccurrences(0))
                                If _deepestLevelBeginTokenIndex.IsInRange("_deepestLevelBeginTokenIndex", 0, 0, False) Then
                                    _tokens.Insert(_deepestLevelBeginTokenIndex, _subexpressionResolutionToken)
                                    _tokens.RemoveRange(_deepestLevelBeginTokenIndex + 1, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1)
                                Else
                                    If _tokens(_deepestLevelBeginTokenIndex - 1).IsOfTypeNot("_tokens(_deepestLevelBeginTokenIndex - 1)", GetType(Fun.FunctionName), False) Then
                                        _tokens.Insert(_deepestLevelBeginTokenIndex, _subexpressionResolutionToken)
                                        _tokens.RemoveRange(_deepestLevelBeginTokenIndex + 1, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1)
                                    Else
                                        Dim _function As Fun.Function = Nothing
                                        Dim _functionFunctionSignature As Fun.FunctionSignature = Nothing
                                        For Each _compilerFunction As Fun.Function In _compiler.Functions
                                            If CType(_tokens(_deepestLevelBeginTokenIndex - 1), Fun.FunctionName).Function.Is("CType(_tokens(_deepestLevelBeginTokenIndex - 1), Fun.FunctionName).Function", _compilerFunction, "_compilerFunction", False) Then
                                                For Each _compilerFunctionFunctionSignature As Fun.FunctionSignature In _compilerFunction.Signatures
                                                    If Fun.FunctionSignature.___IsCompatibleWithParameters(_compilerFunctionFunctionSignature, _subexpressionResolutionToken) Then
                                                        _function = _compilerFunction
                                                        _functionFunctionSignature = _compilerFunctionFunctionSignature
                                                        Exit For
                                                    End If
                                                Next _compilerFunctionFunctionSignature
                                                Exit For
                                            End If
                                        Next _compilerFunction
                                        If _function.IsNull("_function", False) Then
                                            CompilerExpressionFunctionNameAndParametersHaveNoCorrespondingFunctionSignatureException.___Throw(_expression, _tokens.GetRange(_deepestLevelBeginTokenIndex - 1, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1).ToArray())
                                        Else
                                            _tokens.Insert(_deepestLevelBeginTokenIndex - 1, New Fun.FunctionCall(_compiler, _expression, _tokens(_deepestLevelBeginTokenIndex - 1).ExpressionBeginIndex, _tokens(_deepestLevelEndTokenIndex).ExpressionEndIndex, _function, _functionFunctionSignature, New Token() {_subexpressionResolutionToken}))
                                            _tokens.RemoveRange(_deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1)
                                        End If
                                    End If
                                End If
                            Case Else
                                Dim _subexpressionResolutionTokensList As Gen.List(Of Token) = New Gen.List(Of Token)()
                                For _counter As Sys.Int32 = 0 To _deepestLevelSubexpressionsOccurrences.Length - 1
                                    _subexpressionResolutionTokensList.Add(__AssertAndDetermineExpressionResolveSubexpression(_compiler, _expression, _tokens, _deepestLevelSubexpressionsOccurrences(_counter)))
                                Next _counter
                                If _deepestLevelBeginTokenIndex.IsInRange("_deepestLevelBeginTokenIndex", 0, 0, False) Then
                                    CompilerExpressionLevelWhenWithTwoOrMoreParametersMustBePrecededByFunctionNameException.___Throw(_expression, _tokens.GetRange(_deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1).ToArray())
                                Else
                                    If _tokens(_deepestLevelBeginTokenIndex - 1).IsOfTypeNot("_tokens(_deepestLevelBeginTokenIndex - 1)", GetType(Fun.FunctionName), False) Then
                                        CompilerExpressionLevelWhenWithTwoOrMoreParametersMustBePrecededByFunctionNameException.___Throw(_expression, _tokens.GetRange(_deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1).ToArray())
                                    Else
                                        Dim _function As Fun.Function = Nothing
                                        Dim _functionFunctionSignature As Fun.FunctionSignature = Nothing
                                        For Each _compilerFunction As Fun.Function In _compiler.Functions
                                            If CType(_tokens(_deepestLevelBeginTokenIndex - 1), Fun.FunctionName).Function.Is("CType(_tokens(_deepestLevelBeginTokenIndex - 1), Fun.FunctionName).Function", _compilerFunction, "_compilerFunction", False) Then
                                                For Each _compilerFunctionFunctionSignature As Fun.FunctionSignature In _compilerFunction.Signatures
                                                    If Fun.FunctionSignature.___IsCompatibleWithParameters(_compilerFunctionFunctionSignature, _subexpressionResolutionTokensList.ToArray()) Then
                                                        _function = _compilerFunction
                                                        _functionFunctionSignature = _compilerFunctionFunctionSignature
                                                        Exit For
                                                    End If
                                                Next _compilerFunctionFunctionSignature
                                                Exit For
                                            End If
                                        Next _compilerFunction
                                        If _function.IsNull("_function", False) Then
                                            CompilerExpressionFunctionNameAndParametersHaveNoCorrespondingFunctionSignatureException.___Throw(_expression, _tokens.GetRange(_deepestLevelBeginTokenIndex - 1, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1).ToArray())
                                        Else
                                            _tokens.Insert(_deepestLevelBeginTokenIndex - 1, New Fun.FunctionCall(_compiler, _expression, _tokens(_deepestLevelBeginTokenIndex - 1).ExpressionBeginIndex, _tokens(_deepestLevelEndTokenIndex).ExpressionEndIndex, _function, _functionFunctionSignature, _subexpressionResolutionTokensList.ToArray()))
                                            _tokens.RemoveRange(_deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex - _deepestLevelBeginTokenIndex + 1 + 1)
                                        End If
                                    End If
                                End If
                        End Select
                    Else
                        Dim _deepestLevelSubexpressionsOccurrences() As Primitives.Occurrence = Fun.FunctionParametersSeparator.___AssertAndFindFunctionSubexpressionsOccurrences(_expression, _tokens, _deepestLevelBeginTokenIndex, _deepestLevelEndTokenIndex)
                        If _deepestLevelSubexpressionsOccurrences.Length.IsInRangeNot("_deepestLevelSubexpressionsOccurrences.Length", 1, 1, False) Then
                            CompilerExpressionFunctionParametersAreOnlyAllowedInsideLevelsException.___Throw(_expression, _tokens.ToArray())
                        Else
                            Dim _subexpressionResolutionToken As Token = __AssertAndDetermineExpressionResolveSubexpression(_compiler, _expression, _tokens, _deepestLevelSubexpressionsOccurrences(0))
                            _tokens.Clear()
                            _tokens.Add(_subexpressionResolutionToken)
                        End If
                    End If
                Loop
                If _tokens.Count.IsInRange("_tokens.Count", 0, 0, False) Then
                    CompilerExpressionProducedNoEndResultException.___Throw(_expression)
                End If
                Dim _returnValue As Expression = New Expression(_expression, _tokens(0), _tokensVariables)

                Return _returnValue
            End Function

            ''' <exception cref="IsNullException"> </exception>
            ''' <exception cref="IsListFilledNotException"> </exception>
            ''' <exception cref="IsInRangeNotException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionTokenTypeIsValidNotException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionContainsAdjacentValuesOrVariablesOrFunctionCallsException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionContainsAdjacentOperatorsException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionEndsWithOperatorException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionOperatorHasNoCorrespondingFunctionSignatureException"> </exception>
            Private Shared Function __AssertAndDetermineExpressionResolveSubexpression(ByVal _compiler As Compiler, ByVal _expression As System.String, ByVal _tokens As Gen.List(Of Token), ByVal _subexpressionOccurrence As Pri.Occurrence) As Token
                _compiler.IsNullNot("_compiler", True)
                _tokens.IsListFilled("_tokens", True)
                _subexpressionOccurrence.IsNullNot("_subexpressionOccurrence", True)
                _subexpressionOccurrence.BeginIndex.IsInRange("_subexpressionOccurrence.BeginIndex", 0, _tokens.Count - 1, True)
                _subexpressionOccurrence.EndIndex.IsInRange("_subexpressionOccurrence.EndIndex", _subexpressionOccurrence.BeginIndex, _tokens.Count - 1, True)

                Dim _symbolicalString As System.String = __AssertAndDetermineExpressionResolveSubexpressionSymbolicalStringBuild(_tokens, _subexpressionOccurrence.BeginIndex, _subexpressionOccurrence.EndIndex)
                __AssertAndDetermineExpressionResolveSubexpressionSymbolicalStringAssert(_tokens, _subexpressionOccurrence, _symbolicalString)
                Dim _tokensToResolve As Gen.List(Of Token) = _tokens.GetRange(_subexpressionOccurrence.BeginIndex, _subexpressionOccurrence.EndIndex - _subexpressionOccurrence.BeginIndex + 1)
                Do Until _tokensToResolve.Count.IsInRange("_tokensToResolve.Count", 1, 1, False)
                    Dim _auxiliaryList As Gen.List(Of Sys.Object) = __AssertAndDetermineExpressionResolveSubexpressionAuxiliaryListBuild(_tokensToResolve)
                    Dim _maximumOperatorPriority As Sys.Nullable(Of Sys.Int32) = Nothing
                    Dim _maximumOperatorPriorityFunction As Fun.Function = Nothing
                    Dim _maximumOperatorPriorityFunctionFunctionSignature As Fun.FunctionSignature = Nothing
                    Dim _maximumOperatorPriorityParametersList As Gen.List(Of Token) = New Gen.List(Of Token)()
                    Dim _maximumOperatorPrioritySequenceBeginIndex As Sys.Int32 = 0
                    Dim _maximumOperatorPrioritySequenceEndIndex As Sys.Int32 = 0
                    For _counter As Sys.Int32 = 0 To _auxiliaryList.Count - 1
                        If Assert.IsOfType(_auxiliaryList(_counter), "_auxiliaryList(_counter)", GetType(___Operator), False) Then
                            For Each _compilerFunction As Fun.Function In _compiler.Functions
                                If _compilerFunction.Operator.IsNullNot("_compilerFunction.Operator", False) Then
                                    If CType(_auxiliaryList(_counter), ___Operator).Token.IsOfType("CType(_auxiliaryList(_counter),___Operator).Token", _compilerFunction.Operator.Operator, False) Then
                                        For Each _compilerFunctionFunctionSignature As Fun.FunctionSignature In _compilerFunction.Signatures
                                            If (_counter = 0).IsTrue("_counter = 0", False) Then
                                                If Fun.FunctionSignature.___IsCompatibleWithParameters(_compilerFunctionFunctionSignature, CType(_auxiliaryList(_counter + 1), ___Value).Token) Then
                                                    If _maximumOperatorPriority.HasValue.IsTrueNot("_maximumOperatorPriority.HasValue", False) OrElse _maximumOperatorPriority < _compilerFunction.Operator.Priority Then
                                                        _maximumOperatorPriority = _compilerFunction.Operator.Priority
                                                        _maximumOperatorPriorityFunction = _compilerFunction
                                                        _maximumOperatorPriorityFunctionFunctionSignature = _compilerFunctionFunctionSignature
                                                        _maximumOperatorPriorityParametersList.Clear()
                                                        _maximumOperatorPriorityParametersList.Add(CType(_auxiliaryList(_counter + 1), ___Value).Token)
                                                        _maximumOperatorPrioritySequenceBeginIndex = _counter
                                                        _maximumOperatorPrioritySequenceEndIndex = _counter + 1
                                                    End If
                                                End If
                                            Else
                                                If Fun.FunctionSignature.___IsCompatibleWithParameters(_compilerFunctionFunctionSignature, CType(_auxiliaryList(_counter - 1), ___Value).Token, CType(_auxiliaryList(_counter + 1), ___Value).Token) Then
                                                    If _maximumOperatorPriority.HasValue.IsTrueNot("_maximumOperatorPriority.HasValue", False) OrElse _maximumOperatorPriority < _compilerFunction.Operator.Priority Then
                                                        _maximumOperatorPriority = _compilerFunction.Operator.Priority
                                                        _maximumOperatorPriorityFunction = _compilerFunction
                                                        _maximumOperatorPriorityFunctionFunctionSignature = _compilerFunctionFunctionSignature
                                                        _maximumOperatorPriorityParametersList.Clear()
                                                        _maximumOperatorPriorityParametersList.Add(CType(_auxiliaryList(_counter - 1), ___Value).Token)
                                                        _maximumOperatorPriorityParametersList.Add(CType(_auxiliaryList(_counter + 1), ___Value).Token)
                                                        _maximumOperatorPrioritySequenceBeginIndex = _counter - 1
                                                        _maximumOperatorPrioritySequenceEndIndex = _counter + 1
                                                    End If
                                                End If
                                            End If
                                        Next _compilerFunctionFunctionSignature
                                    End If
                                End If
                            Next _compilerFunction
                        End If
                    Next _counter
                    If _maximumOperatorPriority.HasValue.IsTrue("_maximumOperatorPriority.HasValue", False) Then
                        Dim _functionCall As Fun.FunctionCall = New Fun.FunctionCall(_compiler, _expression, _tokensToResolve(_maximumOperatorPrioritySequenceBeginIndex).ExpressionBeginIndex, _tokensToResolve(_maximumOperatorPrioritySequenceEndIndex).ExpressionEndIndex, _maximumOperatorPriorityFunction, _maximumOperatorPriorityFunctionFunctionSignature, _maximumOperatorPriorityParametersList.ToArray())
                        _tokensToResolve.Insert(_maximumOperatorPrioritySequenceBeginIndex, _functionCall)
                        _tokensToResolve.RemoveRange(_maximumOperatorPrioritySequenceBeginIndex + 1, _maximumOperatorPrioritySequenceEndIndex - _maximumOperatorPrioritySequenceBeginIndex + 1)
                    Else
                        CompilerExpressionSubexpressionOperatorHasNoCorrespondingFunctionSignatureException.___Throw(_tokens(_subexpressionOccurrence.BeginIndex).Expression, _tokens.GetRange(_subexpressionOccurrence.BeginIndex, _subexpressionOccurrence.EndIndex - _subexpressionOccurrence.BeginIndex + 1).ToArray())
                    End If
                Loop
                Dim _returnValue As Token = _tokensToResolve(0)

                Return _returnValue
            End Function

            ''' <exception cref="IsNullException"> </exception>
            ''' <exception cref="IsListFilledNotException"> </exception>
            ''' <exception cref="IsInRangeNotException"> </exception>
            Private Shared Function __AssertAndDetermineExpressionResolveSubexpressionSymbolicalStringBuild(ByVal _tokens As Gen.List(Of Token), ByVal _beginIndex As Sys.Int32, ByVal _endIndex As Sys.Int32) As System.String
                _tokens.IsListFilled("_tokens", True)
                _beginIndex.IsInRange("_beginIndex", 0, Sys.Int32.MaxValue, True)
                _endIndex.IsInRange("_endIndex", _beginIndex, Sys.Int32.MaxValue, True)

                Dim _returnValueStringBuilder As Tex.StringBuilder = New Tex.StringBuilder(Sys.String.Empty)
                For _counter As Sys.Int32 = _beginIndex To _endIndex
                    Dim _token As Token = _tokens(_counter)
                    If _token.GetType().IsDerivedOf("_token.GetType()", GetType(Ope.Operator), False) Then
                        _returnValueStringBuilder.Append(__SymbolicalCharacterForOperator)
                    Else
                        If _token.GetType().IsDerivedOf("_token.GetType()", GetType(Val.Value), False) OrElse _token.IsOfType("_token", GetType(Variable), False) OrElse _token.IsOfType("_token", GetType(Fun.FunctionCall), False) Then
                            _returnValueStringBuilder.Append(__SymbolicalCharacterForValue)
                        Else
                            _returnValueStringBuilder.Append(__SymbolicalCharacterForOther)
                        End If
                    End If
                Next _counter

                Return _returnValueStringBuilder.ToString()
            End Function

            ''' <exception cref="IsNullException"> </exception>
            ''' <exception cref="IsListFilledNotException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionTokenTypeIsValidNotException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionContainsAdjacentValuesOrVariablesOrFunctionCallsException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionContainsAdjacentOperatorsException"> </exception>
            ''' <exception cref="CompilerExpressionSubexpressionEndsWithOperatorException"> </exception>
            Private Shared Sub __AssertAndDetermineExpressionResolveSubexpressionSymbolicalStringAssert(ByVal _tokens As Gen.List(Of Token), ByVal _subexpressionOccurrence As Pri.Occurrence, ByVal _symbolicalString As System.String)
                _tokens.IsListFilled("_tokens", True)
                _subexpressionOccurrence.IsNullNot("_subexpressionOccurrence", True)
                _symbolicalString.IsNullNot("_symbolicalString", True)

                Dim _symbolicalStringInvalidTokensOccurrences As Pri.Occurrence() = Pri.String.FindOccurrences(_symbolicalString, __SymbolicalCharacterForOther)
                If _symbolicalStringInvalidTokensOccurrences.Length.IsInRange("_symbolicalStringInvalidTokensOccurrences.Length", 1, Sys.Int32.MaxValue, False) Then
                    CompilerExpressionSubexpressionTokenTypeIsValidNotException.___Throw(_tokens(_subexpressionOccurrence.BeginIndex + _symbolicalStringInvalidTokensOccurrences(0).BeginIndex), _tokens(_subexpressionOccurrence.BeginIndex + _symbolicalStringInvalidTokensOccurrences(0).BeginIndex).GetType())
                End If
                If Pri.String.FindOccurrences(_symbolicalString, __SymbolicalCharacterForValue + __SymbolicalCharacterForValue).Length.IsInRange("Pri.String.FindOccurrences(_symbolicalString, __SymbolicalCharacterForValue + __SymbolicalCharacterForValue).Length", 1, Sys.Int32.MaxValue, False) Then
                    CompilerExpressionSubexpressionContainsAdjacentValuesOrVariablesOrFunctionCallsException.___Throw(_tokens(_subexpressionOccurrence.BeginIndex).Expression, _tokens.GetRange(_subexpressionOccurrence.BeginIndex, _subexpressionOccurrence.EndIndex - _subexpressionOccurrence.BeginIndex + 1).ToArray())
                End If
                If Pri.String.FindOccurrences(_symbolicalString, __SymbolicalCharacterForOperator + __SymbolicalCharacterForOperator).Length.IsInRange("Pri.String.FindOccurrences(_symbolicalString, __SymbolicalCharacterForOperator + __SymbolicalCharacterForOperator).Length", 1, Sys.Int32.MaxValue, False) Then
                    CompilerExpressionSubexpressionContainsAdjacentOperatorsException.___Throw(_tokens(_subexpressionOccurrence.BeginIndex).Expression, _tokens.GetRange(_subexpressionOccurrence.BeginIndex, _subexpressionOccurrence.EndIndex - _subexpressionOccurrence.BeginIndex + 1).ToArray())
                End If
                If ___Texts.EndsWith(_symbolicalString, __SymbolicalCharacterForOperator).IsTrue("___Texts.EndsWith( _symbolicalString,__SymbolicalCharacterForOperator)", False) Then
                    CompilerExpressionSubexpressionEndsWithOperatorException.___Throw(_tokens(_subexpressionOccurrence.BeginIndex).Expression, _tokens.GetRange(_subexpressionOccurrence.BeginIndex, _subexpressionOccurrence.EndIndex - _subexpressionOccurrence.BeginIndex + 1).ToArray())
                End If
            End Sub

            ''' <exception cref="IsNullException"> </exception>
            ''' <exception cref="IsListFilledNotException"> </exception>
            Private Shared Function __AssertAndDetermineExpressionResolveSubexpressionAuxiliaryListBuild(ByVal _tokensToResolve As Gen.List(Of Token)) As Gen.List(Of Sys.Object)
                _tokensToResolve.IsListFilled("_tokensToResolve", True)

                Dim _returnValue As Gen.List(Of Sys.Object) = New Gen.List(Of Sys.Object)()
                For Each _tokenToResolve As Token In _tokensToResolve
                    If _tokenToResolve.GetType().IsDerivedOf("_tokenToResolve.GetType()", GetType(Val.Value), False) Then
                        _returnValue.Add(New ___Value(_tokenToResolve))
                    Else
                        If _tokenToResolve.IsOfType("_tokenToResolve", GetType(Variable), False) Then
                            _returnValue.Add(New ___Value(_tokenToResolve))
                        Else
                            If _tokenToResolve.IsOfType("_tokenToResolve", GetType(Fun.FunctionCall), False) Then
                                _returnValue.Add(New ___Value(_tokenToResolve))
                            Else
                                _returnValue.Add(New ___Operator(CType(_tokenToResolve, Ope.Operator)))
                            End If
                        End If
                    End If
                Next _tokenToResolve

                Return _returnValue
            End Function

        End Class
    End Class
End Namespace
